using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace CoVuaCtrl
{
    public class QuanVua: QuanCo
    {
        int[] xArr = {1, 1, 1, 0, -1, -1, -1, 0};
        int[] yArr = {-1, 0, 1, 1, 1, 0, -1, -1};

        public OCo[] layNuocDi(BanCo bc)
        {
            OCo[] result = null;
            ArrayList arr = new ArrayList();
            int x = layViTri().layX();
            int y = layViTri().layY();

            for (int i = 0; i < xArr.Length; ++i)
            {
                int xTemp = x + xArr[i];
                int yTemp = y + yArr[i];
            
                if (xTemp >= 0 && xTemp < 8 && yTemp >= 0 && yTemp < 8 && bc.layQuanCo(xTemp, yTemp) == null)
                    arr.Add(new OCo(xTemp, yTemp));
            }

            if (arr.Count != 0)
                for (int i = 0; i < arr.Count; i++)
                    result[i] = (OCo)arr[i];

            return result;
        }

        public QuanCo[] layDSQuanCoBiAn(BanCo bc)
        {
            QuanCo[] result = null;
            ArrayList arr = new ArrayList();
            int x = layViTri().layX();
            int y = layViTri().layY();

            for (int i = 0; i < xArr.Length; ++i)
            {
                int xTemp = x + xArr[i];
                int yTemp = y + yArr[i];

                if (xTemp >= 0 && xTemp < 8
                    && yTemp >= 0 && yTemp < 8
                    && bc.layQuanCo(xTemp, yTemp) != null
                    && bc.layQuanCo(xTemp, yTemp).layNguoiChoi().sosanh(layNguoiChoi()) == false)
                {
                    arr.Add(bc.layQuanCo(xTemp, yTemp));
                }
            }

            if (arr.Count != 0)
                for (int i = 0; i < arr.Count; i++)
                    result[i] = (QuanCo)arr[i];

            return result;
        }
    }
}
